﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;

using Blackbird.Utilities;

namespace Blackbird.Network
{
    /// <summary>
    /// A class which acts as a MUS server for decoding logic of the banner.png & client encryption.
    /// </summary>
    class MusServer
    {
        /// <summary>
        /// The listening socket for the MUS class.
        /// </summary>
        private Socket MUSSocket;

        /// <summary>
        /// The callback for a connection request.
        /// </summary>
        private AsyncCallback ConnectionCallback;

        /// <summary>
        /// The port for the listener.
        /// </summary>
        private int Port;

        /// <summary>
        /// The logging instance of the class.
        /// </summary>
        private Log log;


        /// <summary>
        /// Construct a new MUS instance.
        /// </summary>
        /// <param name="Port">The port to be setup for MUS.</param>
        /// <param name="LocalEndpoint">The IPEndpoint of the MUS server instance.</param>

        public MusServer(int Port, IPEndPoint LocalEndpoint)
        {
            this.Port = Port;
            this.Port = LocalEndpoint.Port;
            this.log = new Log("MUSServer");
            this.MUSSocket = new Socket(LocalEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            this.MUSSocket.Bind(LocalEndpoint);
            this.MUSSocket.Listen(5);
            this.log.Info("MUS Server is now ready for use.");
            this.StartAccept();
            
        }

        private void StartAccept()
        {
            this.MUSSocket.BeginAccept(this.ConnectionCallback, this.MUSSocket);
        }
        private void OnAccept(IAsyncResult IAr)
        {
            Socket TmpSocket = this.MUSSocket.EndAccept(IAr);
            
        }
    }
}
